import {Component, OnInit} from '@angular/core';
import {UserService} from "./user.service";
import {ActivatedRoute, Params, Router} from "@angular/router";

@Component({
  selector: 'app-user',
  templateUrl: './user.component.html',
  styleUrls: ['./user.component.css']
})
export class UserComponent implements OnInit {

  constructor(
    private userService: UserService,
    private router:Router,
    private route:ActivatedRoute
  ) {
  }

  ngOnInit(): void {
    this.route.queryParams.subscribe(
      (params: Params) => {
        if (params['token']&&params['nickName']&&params['phoneNum']){
          this.token = params['token'];
          this.nickName = params['nickName'];
          this.phoneNum = params['phoneNum'];
        }
    });
    this.getUserInfo()
    // if (this.token==''){
    //   this.router.navigate(['login'])
    // }
  }

  token = ''
  nickName = 'login_test'
  phoneNum = '12345678910'

  getUserInfo() {
    this.userService.getInfoService(this.token).subscribe(
      data => {
        this.nickName = data.nickName
        this.phoneNum = data.phoneNum
        console.log(data)
      }
    )
  }

  register(){
    return this.router.navigate(['login'])
  }
}
